package com.ruoyi.helpMove.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.weChatRobot.utils.WechatRobotUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.helpMove.domain.SysMoveFinish;
import com.ruoyi.helpMove.service.ISysMoveFinishService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 帮扶移交Controller
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/helpMove")
public class SysMoveFinishController extends BaseController
{
    @Autowired
    private ISysMoveFinishService sysMoveFinishService;


    /**
     * 帮扶移交发送邮件
     */
    @Log(title = "帮扶移交", businessType = BusinessType.INSERT)
    @PostMapping("/sentEmail")
    public void sentEmail(@RequestBody SysMoveFinish sysMoveFinish)
    {
        sysMoveFinishService.sentEmail(sysMoveFinish);
    }
    /**
     * 查询帮扶移交列表
     */
    @RequiresPermissions("employment:helpMove:list")
    @GetMapping("/list")
    public TableDataInfo list(SysMoveFinish sysMoveFinish)
    {
        startPage();
        List<SysMoveFinish> list = sysMoveFinishService.selectSysMoveFinishList(sysMoveFinish);
        return getDataTable(list);
    }

    /**
     * 导出帮扶移交列表
     */
    @RequiresPermissions("employment:helpMove:export")
    @Log(title = "帮扶移交", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMoveFinish sysMoveFinish)
    {
        List<SysMoveFinish> list = sysMoveFinishService.selectSysMoveFinishList(sysMoveFinish);
        ExcelUtil<SysMoveFinish> util = new ExcelUtil<SysMoveFinish>(SysMoveFinish.class);
        util.exportExcel(response, list, "帮扶移交数据");
    }

    /**
     * 获取帮扶移交详细信息
     */
    @RequiresPermissions("employment:helpMove:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMoveFinishService.selectSysMoveFinishById(id));
    }

    /**
     * 新增帮扶移交
     */
    @RequiresPermissions("employment:helpMove:add")
    @Log(title = "帮扶移交", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMoveFinish sysMoveFinish)
    {
        String message ="帮扶已经移交"+"\n"+"移交人:@"+sysMoveFinish.getMoveName()+"\n"+"被移交人:@"+sysMoveFinish.getAccpectName()
                +"\n"+"移交时间："+sysMoveFinish.getCreatTime()+"\n"+"原因:"+sysMoveFinish.getMoveRemark();
        WechatRobotUtil.sendTextMessage(message,new ArrayList());
        return toAjax(sysMoveFinishService.insertSysMoveFinish(sysMoveFinish));
    }

    /**
     * 修改帮扶移交
     */
    @RequiresPermissions("employment:helpMove:edit")
    @Log(title = "帮扶移交", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMoveFinish sysMoveFinish)
    {
        return toAjax(sysMoveFinishService.updateSysMoveFinish(sysMoveFinish));
    }

    /**
     * 删除帮扶移交
     */
    @RequiresPermissions("employment:helpMove:remove")
    @Log(title = "帮扶移交", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMoveFinishService.deleteSysMoveFinishByIds(ids));
    }
}
